<?php
class User_LoginController extends Zend_Controller_Action{
	public function init(){
		$this->_helper->layout()->setLayout('register_login');
		$this->_SESSION=new Zend_Session_Namespace();
	}
	public function indexAction(){
		if(isset($this->_SESSION->iduser))
			header("location: http://localhost/hoidap/Source/user");
	}
	
	public function loginxulyAction(){
		$this->_helper->viewRenderer->setNoRender(true);
		$this->_helper->layout->disableLayout();
		
		$email = $_POST['email'];
		$password = $_POST['password'];
		
		$user = new User_Model_DbTable_Users();
		$info = $user ->checkemailpassword($email, $password);
		//print_r($info);
		
		if($info==0)
			$flag = 0;
		else{
			$this->_SESSION->iduser=$info[0]['id'];
			$this->_SESSION->firstname=$info[0]['user_firstname'];
			$this->_SESSION->lastname=$info[0]['user_lastname'];
			$flag = 1;
		}
		$kq=array('ketqua'=>$flag);
		echo Zend_Json::encode($kq);
	}
	
	public function dangxuatAction(){
		$this->_helper->viewRenderer->setNoRender(true);
		$this->_helper->layout->disableLayout();
		unset ($this->_SESSION->iduser);
		unset ($this->_SESSION->firstname);
		unset ($this->_SESSION->lastname);
		header("location: http://localhost/hoidap/Source/user/login");
		//echo 'dang xuat';
	}
	
}